﻿namespace ImageProcessing.ImageProcessor
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// positio Structure
    /// </summary>
    public struct Position
    {
        /// <summary>
        /// x positions
        /// </summary>
        private int x;

        /// <summary>
        /// y positions
        /// </summary>
        private int y;

        /// <summary>
        /// Gets or sets the X.
        /// </summary>
        /// <value>
        /// The X.
        /// </value>
        public int X
        {
            get { return this.x; }
            set { this.x = value; }
        }

        /// <summary>
        /// Gets or sets the Y.
        /// </summary>
        /// <value>
        /// The Y.
        /// </value>
        public int Y
        {
            get { return this.y; }
            set { this.y = value; }
        }
    }

    /// <summary>
    /// IMG_PerfectRandom class
    /// </summary>
    public class IMG_PerfectRandom
    {
        /// <summary>
        /// img pixels as 1D array
        /// </summary>
        private int[] imgPixels;

        /// <summary>
        /// random instance
        /// </summary>
        private Random rand;

        /// <summary>
        /// tail value
        /// </summary>
        private int tail;

        /// <summary>
        /// Initializes a new instance of the <see cref="IMG_PerfectRandom"/> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        public IMG_PerfectRandom(int width, int height)
        {
            try
            {
                this.imgPixels = new int[width * height];
                for (int i = 0; i < width * height; i++)
                {
                    this.imgPixels[i] = i;
                }

                this.tail = (width * height) - 1;
                this.rand = new Random();
            }
            catch (Exception img_Ex)
            {
                Logger.LogException(img_Ex);
                throw;
            }
        }

        /// <summary>
        /// get next perfect random.
        /// </summary>
        /// <returns>the position</returns>
        public int IMG_GetNextPerfectRandom()
        {
            try
            {
                if (this.tail < 0)
                {
                    return 0;
                }

                int index = this.rand.Next(0, this.tail);
                int returnVal = this.imgPixels[index];
                this.imgPixels[index] = this.imgPixels[this.tail];
                this.tail--;
                return returnVal;
            }
            catch (Exception img_Ex)
            {
                Logger.LogException(img_Ex);
                throw;
            }
        }
    }
}
